﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

// AreaName lcl ( [language] [, [user-context] [, [label-type] ]] )
public class MetadataAreaNameDeclaration : Declaration
{
    private StringLiteral? _labelType;


    private StringLiteral? _languageName;
    private StringLiteral? _userContext;

    internal MetadataAreaNameDeclaration(SyntaxToken declareKeywordToken, Identifier name, SyntaxNode? parent) :
        base(SyntaxKinds.MetadataAreaName, declareKeywordToken, name, parent)
    {
    }

    /// <summary>
    ///     语言名称
    /// </summary>
    public StringLiteral? LanguageName => _languageName;


    /// <summary>
    ///     用户上下文类型
    /// </summary>
    public StringLiteral? UserContext => _userContext;


    /// <summary>
    ///     标签上下文类型
    /// </summary>
    public StringLiteral? LabelType => _labelType;


    public MetadataAreaNameDeclaration Update(StringLiteral? languageName, StringLiteral? userContext,
        StringLiteral? labelType)
    {
        SetChildNullableField(ref _languageName, languageName);
        SetChildNullableField(ref _userContext, userContext);
        SetChildNullableField(ref _labelType, labelType);
        return this;
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, DeclareKeywordToken, NameIdentifier,
            LanguageName, UserContext, LabelType);
    }
}


public static partial class NodeFactory
{
    public static MetadataAreaNameDeclaration CreateMetadataAreaNameDeclaration(SyntaxNode? parent,
        SyntaxToken declareKeywordToken, Identifier identifierName, StringLiteral? languageName,
        StringLiteral? userContext, StringLiteral? labelType)
    {
        Debug.Assert(declareKeywordToken.IsNode(SyntaxKinds.LclKeywordToken));
        MetadataAreaNameDeclaration areaName = new(declareKeywordToken, identifierName, parent);
        return areaName.Update(languageName, userContext, languageName);
    }
}